//
//  CLHTableViewCollectionViewTVCellModel.m
//  ListViewModel_Example
//
//  Created by 曹连华 on 2019/7/31.
//  Copyright © 2019 clh2046@163.com. All rights reserved.
//

#import "CLHTableViewCollectionViewTVCellModel.h"
#import "CLHTableViewCollectionViewCVCellModel.h"

@implementation CLHTableViewCollectionViewTVCellModel
- (LVCollectionViewDataSource *)dataSource {
    if (!_dataSource) {
        _dataSource = [[LVCollectionViewDataSource alloc]init];
    }
    return _dataSource;
}
- (instancetype)initWithCellClass:(NSString *)cellClassStr {
    self = [super initWithCellClass:cellClassStr];
    if (self) {
        [self.dataSource resetSectionList:[self sections]];
        self.canEdit = YES;//若 没设置或者设置为NO 则 该行 不能编辑
        self.editingStyle = UITableViewCellEditingStyleDelete;// 与 canEdit 同时设置
    }
    return self;
}
- (NSArray <LVBaseCellSectionModel *> *)sections {
    
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0 ; i < 1; i ++) {
        int arc = i%2;
        
        if (arc == 0) {
            LVBaseCellSectionModel *sectionModel = [[LVBaseCellSectionModel alloc]initWithRowList:[self row0s]];
            
            sectionModel.sectionHeader = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionHeader" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30) ];
            sectionModel.sectionHeader.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionHeaderView",i];
            
            sectionModel.sectionFooter = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionFooter" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30) ];
            sectionModel.sectionFooter.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionFooterView",i];
            
            [arr addObject:sectionModel];
        } else {
            LVBaseCellSectionModel *sectionModel = [[LVBaseCellSectionModel alloc]initWithRowList:[self row1s]];
            
            sectionModel.sectionHeader = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionHeader" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30) ];
            sectionModel.sectionHeader.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionHeaderView",i];
            
            sectionModel.sectionFooter = [[LVBaseSectionHeaderFooterModel alloc]initWithReuseIdentifier:@"sectionFooter" size:CGSizeMake([UIScreen mainScreen].bounds.size.width, 30) ];
            sectionModel.sectionFooter.headerFooterTitle = [NSString stringWithFormat:@"section = %d 的 sectionFooterView",i];
            
            [arr addObject:sectionModel];
        }
        
    }
    return arr;
}

- (NSArray <CLHTableViewCollectionViewCVCellModel *> *)row0s {
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < 15; i++) {
        CLHTableViewCollectionViewCVCellModel *row = [[CLHTableViewCollectionViewCVCellModel alloc]initWithCellClass:@"CLHTableViewCollectionViewCVCell"];
        row.mainTitle = [NSString stringWithFormat:@"row = %d",i];
        row.rowHeight = 50;
        [arr addObject:row];
    }
    return arr;
}

- (NSArray <CLHTableViewCollectionViewCVCellModel *> *)row1s {
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < 15; i++) {
        CLHTableViewCollectionViewCVCellModel *row = [[CLHTableViewCollectionViewCVCellModel alloc]initWithCellClass:@"CLHTableViewCollectionViewCVCell"];
        row.mainTitle = [NSString stringWithFormat:@"row = %d",i];
        row.rowHeight = 50;
        [arr addObject:row];
    }
    return arr;
}
@end
